import cv2
import oss2
import pymysql


def save_rtsp_img(rtsp_path, img_name):
    cap = cv2.VideoCapture(rtsp_path)
    ret, frame = cap.read()
    cv2.imwrite(filename="image/" + img_name + ".jpg", img=frame)
    auth = oss2.Auth('LTAI4G9UbPy1UCF2LKZ6tk7C', 'mWWWeUEiYKR7UqjbDlL3x1hIQP6usn')
    bucket = oss2.Bucket(auth, 'http://oss-cn-beijing.aliyuncs.com', 'iotdb-bak')
    bucket.put_object_from_file('ai/point/test2.jpg', 'image/' + img_name + ".jpg")
    # 连接数据库
    conn = pymysql.Connect(
        host='192.168.1.191',
        port=3306,
        user='root',
        passwd='root',
        db='customer_ai',
        charset='utf8'
    )
    # 获取游标
    cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
    cursor.execute(
        "update camera_pic_point set camera_pic_url ='222.jpg' where camera_index_code='36010000581314013757';")


rtsp_path = "rtsp://121.36.135.122:554/openUrl/T1vL05O"
img_name = "buchou"
save_rtsp_img(rtsp_path, img_name)
